home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
examples
/
programs
/
playback.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-08
|
10KB
|
278 lines
#ifndef lint
static char SccsId[]= "@(#)playback.c V1.32 3/13/95";
#endif
/*
| file name - playback.c
|===================================================================
|
| This example works similarly to DVplay. It plays back a view
| created in DV-Draw. It continuously updates the view until the
| user selects the <q|Q> key or right mouse button. The program
| will also exit if the user selects an object named "quit".
|
|===================================================================
*/
#include <windows.h>
/*
* DV-Tools header files
*/
#include "std.h" /* <stdio.h> etc., scalar & macro definitions */
#include "dvstd.h" /* public types & constants */
#include "dvtools.h" /* constants used by T routines */
#include "dvGR.h" /* constants used by window mgt & GR routines */
#include "VOstd.h" /* constants used by VO & VOob routines */
#include "Tfundecl.h" /* T routines (screens, drawports & views) */
#include "VOfundecl.h" /* VO routines (objects) */
#include "VUerfundecl.h" /* VUer routines (event handling routines) */
/* Constants */
#define DVPATH (char *)NULL
#define DISPFORMS_STB (char *)NULL
#define DVDEVICE (char *)NULL
#define DVCOLORTABLE (char *)NULL
#define VIEW_NAME "play.v"
#define SCREEN_VIEWPORT (RECTANGLE *)NULL
#define DRAWING_VIEWPORT (RECTANGLE *)NULL
/*
* MAIN PROGRAM
*/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
INT argc = 0;
CHAR **argv;
/*
* program arguments
* argv[1] - display device name (default is to use DVDEVICE)
* argv[2] - view name (default is play.v)
*/
/* Define & initialize device name and view filename */
char *device_name = DVDEVICE; /* default device name */
char *view_name = VIEW_NAME; /* default view name */
/* Define display variables */
OBJECT screen; /* display device, the window */
DRAWPORT drawport; /* how & where to display picture, picture frame */
VIEW view; /* picture representation of the view file */
/* Control loop variables */
OBJECT location; /* the event representation */
int event_status; /* the status of event requests */
char *obj_name; /* name of selected graphical object */
/* Other variables */
int Quit = NO; /* flag to quit program */
/*--------------------
* Initialization
*
* TInit: perform the initialization of DV-Tools
* TInit reads your configuration file and any
* environment variables or logical names set.
*/
make_argv(&argc,&argv,GetCommandLine());
TInit( DVPATH, DISPFORMS_STB );
/*
* TscOpenSet: open a device as a screen object using
* specified attributes
* TscErase: erase the entire screen in the default
* background color
*
* Set exposure block to YES to insure the window
* is ready for drawing when TdpDraw is called.
*/
if (argc > 1)
device_name = argv[1];
screen = TscOpenSet (device_name, DVCOLORTABLE,
V_X_EXPOSURE_BLOCK, YES,
V_ACTIVE_CURSOR, V_END_OF_LIST);
if (!screen)
{
printf ("Must specify device on command line or");
printf (" in DataViews configuration file.\n");
S_EXIT (EXIT_ERR);
}
TscErase (screen);
/*
* VOscWinEventMask: sets the screen's window event mask
*/
VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
V_BUTTONPRESS | V_BUTTONRELEASE | V_MOTIONNOTIFY,
(ULONG) 0);
/*
* TviLoad: Load a view in from a file, either a
* user supplied view or default view file play.v
* TdpCreate: Create a DV-Tools window, a drawport.
* The drawport is attached to the screen object
* specified while view specifies the view to be
* displayed on the screen.
*/
if (argc == 3)
view_name = argv[2];
view = TviLoad (view_name);
if (!view)
{
printf ("Could not load view from file ");
printf ("%s.\n", view_name);
S_EXIT (EXIT_ERR);
}
drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
/*
* TviOpenData: Open all data source lists for this view and views
* referenced by enabled subdrawings contained in view
* TviReadData: Reads data from the data sources of a view
*/
TviOpenData (view);
TviReadData (view);
/*
* TdpDraw: Draw the contents of a drawport
*/
TdpDraw (drawport);
/*--------------------
* Control loop
*
* Poll the event queue for window events specified by the
* window mask. Handle each of the events as they happen.
* Events occurring within input objects will be handled
* through the event request handler VUerHandleLocEvent.
* Draw successive updates of the view after reading a data
* iteration. Stop when the user selects "q|Q", the
* right mouse button, or selects an object named "quit".
*/
FOREVER
{
/*
* VOloWinEventPoll: Poll for the next window event.
* The polling mode used is V_NO_WAIT.
* Using this mode, VOloWinEventPoll
* does not wait until a masked event
* is generated.
*
* VUerHandleLocEvent: Service the event. This routine will check
* if the event is used by any input objects
* that may be in the view.
*/
location = VOloWinEventPoll (V_NO_WAIT);
if (location)
{
event_status = VUerHandleLocEvent (location);
/*
* If the return value of VUerHandleLocEvent is INPUT_UNUSED
* then check for keypress or buttonpress events which
* represent one of the exit keys as well as checking if
* an object was selected which has a name of "quit".
*/
if (event_status == INPUT_UNUSED)
{
/*
* VOloType: returns the type of event. These types
* match event types specified in VOscWinEventMask.
*/
switch (VOloType (location))
{
case V_KEYPRESS:
/*
* Check key selected.
* VOloKeySym: Returns the key symbol value of the
* location object
* TloGetSelectedObjectName: Get the name of the
* selected object
*
* If the key symbol represents the characters 'q'
* or 'Q' then quit the program.
* Any ascii key acts as a possible selection key. A
* selected object with the name "quit" exits the program.
*/
switch (VOloKeySym (location))
{
case 'q':
case 'Q':
Quit = YES;
break;
default:
if ((obj_name = TloGetSelectedObjectName (location)) &&
(strcmp (obj_name, "quit") == 0))
Quit = YES;
break;
}
break;
case V_BUTTONPRESS:
/*
* Check button selected.
* VOloButton: Returns the button that was pressed
* TloGetSelectedObjectName: Get the name of the
* selected object
*
* The left mouse button acts as the selection button. A
* selected object with the name "quit" signifies the exit
* of the program. The right mouse button exits the program.
*/
switch (VOloButton (location))
{
case 1:
if ((obj_name = TloGetSelectedObjectName (location)) &&
(strcmp (obj_name, "quit") == 0))
Quit = YES;
break;
case 3:
Quit = YES;
break;
default:
break;
}
break;
case V_MOTIONNOTIFY:
default:
break;
}
}
}
/* exit the program */
if (Quit == YES)
break;
/*
* TviReadData: Read data from the data sources of the view.
* TdpDrawNext: Update all dynamic objects within a drawport's view
*/
TviReadData (view);
TdpDrawNext (drawport);
}
/*--------------------
* Termination
*
* TdpDestroy: Destroy the drawport,
* TviCloseData: Close the data sources of the view
* TviDestroy: Destroy the view, freeing the allocated memory
* TscClose: Closes the screen object
* TTerminate: Perform the clean-up for DV-Tools
*/
TdpDestroy (drawport);
TviCloseData (view);
TviDestroy (view);
TscClose (screen);
TTerminate ();
return (EXIT_OK);
}